package com.sjzd.discoveryserviceprovider.service02;

import com.sjzd.discoveryserviceprovider.ProviderUser;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author ZFQ
 * @date 2022/2/13
 */
@SpringBootApplication
@RestController
@RequestMapping("/service")
public class ServiceController02 {

    public static void main(String[] args) {
        SpringApplication.run(ServiceController02.class, args);
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello, i am service02";
    }

    @RequestMapping("/error")
    public void error(HttpServletResponse resp) {
        resp.setStatus(500);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.write("出错了");
        writer.close();
        writer.flush();
    }

    @RequestMapping("/echo")
    public String echo(String command) {
        return command;
    }

    @RequestMapping("/user")
    public String echo(@RequestBody ProviderUser user) {
        return user.toString();
    }
}
